<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page, index) in pages" :key="index">
        <div class="icon" v-for="item in page" :key="item.id">
          <div class="icon-img" >
            <img class="icon-img-content" :src="item.imgUrl">
          </div>
          <p class="icon-text">{{item.desc}}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'homeIcons',
  props: {
    iconListReal: Array
  },
  data () {
    return {
      swiperOption: {
        // pagination: ".swiper-pagination",
        autoplay: false,
        loop: true,
        initialSlide: 1
      },
      swiperList: [{
        id: '1',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
        text: '景点门票'
      }, {
        id: '2',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png',
        text: '一日游'
      }, {
        id: '3',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/4c/eac47dd8def8de02.png',
        text: '园博园'
      }, {
        id: '4',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/6c/9e54a8540fee0102.png',
        text: '故宫'
      }, {
        id: '5',
        imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20193/338c5b924c5809e8c7b14f60a953c3e2.png',
        text: '重庆欢乐谷'
      }, {
        id: '6',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/67/9a1678221b8e0e02.png',
        text: '古北水镇'
      }, {
        id: '7',
        imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20193/a40ee278d67000f2a29d2e20f6a029b3.png',
        text: '香山公园'
      }, {
        id: '8',
        imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20193/a40ee278d67000f2a29d2e20f6a029b3.png',
        text: '凤凰岭'
      }, {
        id: '9',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/bd/9f7b9b2b60c1502.png',
        text: '踏青赏花'
      }, {
        id: '10',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/47/c2b659e048b11602.png',
        text: '中国马镇'
      }]
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconListReal.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang = "stylus" scoped>
  @import '../../../assets/styles/varibles.styl'
  .icons >>> .swiper-container
    height: 0
    padding-bottom: 52%
    color: #eee
  .icon
    /* margin-top: .1rem */
    overflow: hidden
    position: relative
    float: left
    height: 0
    width: 25%
    padding-bottom: 25%
    margin-top: .1rem
    /* background: #ff0000 */
    .icon-img
      position: absolute
      top: 0
      left: 0
      right: 0
      bottom: .44rem
      margin: .1rem
      /* background: blue */
      .icon-img-content
        display: block
        margin: 0 auto
        height: 100%
    .icon-text
      color: $darkTextColor
      position: absolute
      bottom: 0
      left: 0
      right: 0
      hight: .5rem
      line-height: .5rem
      text-align: center
      overflow: hidden
      white-space: nowrap
      text-overflow: ellipsis
</style>